<?php
/**
 * 
 * 物流地址信息
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-5-05
 * model() 创建模型对象，静态
 * tableName() 返回表名
*/

class Addr extends CActiveRecord{
	/**
	 *返回当前模型对象的方法 
	 */
	public static function model($className = __CLASS__){
		return parent::model($className);
	}
	
	/**
	 * 返回当前表名
	 */
	public function tableName(){
		return '{{addr}}';
	}
	
	
	//存入物流信息
	public function setAddr($user_id){
		$cmodel = new CCCModel();
		$_sql = "INSERT INTO {{addr}}(
								`user_id`,
								`addr_pro`,
								`addr_city`,
								`addr_country`,
								`addr_details`,
								`addr_zip`,
								`addr_reciver_name`,
								`addr_tel`,
								`addr_default`,
								`addr_sort`,
								`active`
							) VALUES(
								$user_id,
								'".$_POST['province']."',
								'".$_POST['city']."',
								'".$_POST['county']."',
								'".$_POST['addr_details']."',
								'".$_POST['addr_zip']."',
								'".$_POST['addr_reciver_name']."',
								'".$_POST['addr_tel']."',
								'".$_POST['addr_default']."',
								'".$_POST['addr_sort']."',
								'".$_POST['active']."'
							)";
		
		$row = $cmodel->upd($_sql);
		return $row;
	}
	
	
	//根据用户id读取物流信息
	public function getAddrByUserId($user_id){
		
		$all_model = new CCCModel();
		$_sql = "SELECT * FROM {{addr}}  WHERE user_id=$user_id ORDER BY addr_sort ASC";
		$result = $all_model->sel($_sql);
		return $result;
	}
	
//根据用户id读取详细信息
		public function geUserByUserId($user_id){
		
		$all_model = new CCCModel();
		$_sql = "SELECT * FROM {{user}}  WHERE user_id=$user_id";
		$result = $all_model->sel($_sql);
		return $result;
	}
	
	//根据地址id读取物流地址信息
	public function getAddrByAddrId($addr_id){
		$all_model = new CCCModel();
		$_sql = "SELECT * FROM {{addr}}  WHERE addr_id=$addr_id";
		$result = $all_model->sel($_sql);
		return $result;
	}
	
	//根据id修改地址信息
	public function updAddr($addr_id){
		$cmodel = new CCCModel();
		$_sql = "UPDATE {{addr}} SET 
							addr_pro = '".$_POST['province']."',
							addr_city = '".$_POST['city']."',
							addr_country = '".$_POST['county']."',
							addr_details = '".$_POST['addr_details']."',
							addr_zip = '".$_POST['addr_zip']."',
							addr_reciver_name = '".$_POST['addr_reciver_name']."',
							addr_tel = '".$_POST['addr_tel']."',
							addr_default = '".$_POST['addr_default']."',
							addr_sort = '".$_POST['addr_sort']."',
							active = '".$_POST['active']."'
		WHERE  addr_id = $addr_id";
		$row = $cmodel->upd($_sql);
		return $row;
	} 

}
	
?>